/**
 * Created by ospip on 2017/10/17.
 * Copyright (c) 2017 LLAP. All rights reserved.
 */
public class ScoreAverage implements Average {
    double[] list;

    public ScoreAverage(double[] l) {
        list = l;
    }

    public ScoreAverage(String[] l) {
        list = new double[l.length];
        try {
            for (int i = 0; i < l.length; i++) {
                list[i] = Double.parseDouble(l[i]);
            }

        }
        catch (NumberFormatException e) {
            System.out.println(e.getMessage());
        }
    }

    @Override
    public double average() {
        if (list.length < 2) throw new ArithmeticException("Divided By 0");
        double cnt = 0, max = 0x80000000, min = 0x7fffffff, sum = 0;
        for (double i : list) {
            sum += i;
            if (i > max) max = i;
            if (i < min) min = i;
            cnt += i;
        }
        cnt -= 2;
        sum = sum - max - min;
        return sum / cnt;
    }
}
